package logger

import (
	"log/slog"
	"sync"
)

var (
	moduleHandlers = make(map[string]*slog.Logger)
	mu             sync.RWMutex
)

// Module gets a module logger
func Module(moduleName string) *slog.Logger {
	if !IsInitialized() {
		panic("logger system not initialized")
	}

	mu.RLock()
	defer mu.RUnlock()

	if logger, exists := moduleHandlers[moduleName]; exists {
		return logger
	}

	// If module logger doesn't exist, use default logger with module field
	return Default()
}
